import Vue from 'vue'
import Vuex from 'vuex'

import storage from '@/util/storage.js'
import moment from 'moment'

Vue.use(Vuex);

const store = new Vuex.Store({
	state:{
		status_bar_height: 32,
		window_height: 1800,
		width_pixel_ratio: 1,
		user_token: storage.getStorageSync('user_token') || '',
		user_data: storage.getStorageSync('user_data') || '',
		date_str: moment().format('YYYY-MM'),
		show_yusuan: storage.getStorageSync('show_yusuan') || true
	},
	getters: {
		
	},
	actions: {
		
	},
	mutations: {
		getSystemInfo(state){
			let {statusBarHeight, windowHeight, devicePixelRatio, windowWidth} = uni.getSystemInfoSync()
			console.log(statusBarHeight, windowHeight, devicePixelRatio, windowWidth)
			state.status_bar_height = statusBarHeight
			state.window_height = windowHeight
			state.width_pixel_ratio = windowWidth / 750
		},
		setStatusBarHerght(state, val = 0){
			state.status_bar_height = val
		},
		setUserToken(state, val){
			state.user_token = val
			storage.setStorage('user_token', val)
		},
		setUserData(state, val){
			state.user_data = val
			storage.setStorage('user_data', val)
		},
		setDateStr(state, val){
			state.date_str = val
		},
		setShowYusuan(state, val){
			state.show_yusuan = val
			storage.setStorage('show_yusuan', val)
		}
	}
})

export default store